/*
 * processRequest.h
 *
 *  Created on: Nov 28, 2011
 *      Author: Danny
 */

#ifndef PROCESSREQUEST_H_
#define PROCESSREQUEST_H_
#include <stdlib.h>
#include <time.h>

/*
 * TIME_CALL must be last element to ensure sysCallSize() - 1
 * returns a number that represents the number of sys_calls that
 * are not Timer related as a process cannot throw a timer request.
 */
typedef enum int_handle_enum {
	IO_SYS_CALL,
	SEM_DOWN_SYS_CALL,
	SEM_UP_SYS_CALL,
	MEM_WRITE_SYS_CALL,
	MEM_READ_SYS_CALL,
	TIME_CALL} sys_call;

/*
 * Total size of sys_call enum divided by the standard size of an int
 * should return the number of elements in the enum.
 */
int sysCallSize() {
	int size = sizeof(sys_call) / sizeof(int);
	printf("number of elements in sys_call = %d\n" + size);
	fflush(stdout);
	return sizeof(sys_call) / sizeof(int);
}

typedef struct ProcessRequest {
	int interuptTime;
	sys_call requestMessage;
} stProcessRequest;

/*
 * Construct a stProcessRequest with a random interuptTime between
 * 1 and a randomMax int passed in and a random sys_call message
 */
stProcessRequest* createProcessRequest(int randomMax) {
	// srand(time(NULL));
	stProcessRequest *request;
	request->interuptTime = rand() % randomMax + 1; // a number between 1 and randomMax
	request->requestMessage = rand() % (sysCallSize() - 1); // a number between 0 and number of elements in sys_call enum that are not Timer related.
	return request;
}


#endif /* PROCESSREQUEST_H_ */
